/**
 * Drag and drop test
 */
const { ipcMain } = require('electron')
const pathModule = require('path')
const fs = require('fs')

module.exports = () => {
  const resourceFolder = pathModule.join(process.cwd(), 'resources')
  const iconName = pathModule.join(resourceFolder, 'iconForDragAndDrop.png')

  // mock some test files for drag and drop
  fs.writeFileSync(pathModule.join(resourceFolder, 'drag-and-drop-1.md'), "# First fileto test drag and drop")
  fs.writeFileSync(pathModule.join(resourceFolder, 'drag-and-drop-2.md'), "# Second fileto test drag and drop")

  // add listener from main world
  ipcMain.on('ondragstart', (event, filename) => {
    // received from main world
    const fileFullPath = pathModule.join(resourceFolder, filename)
    console.info('main -> ondragstart: ', fileFullPath)
    // call file sender function to send file to target folder with icon
    event.sender.startDrag({
      file: fileFullPath,
      icon: iconName,
    })
  })
}